package com.mqtt.ctwingmqtt.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.mqtt.ctwingmqtt.domain.entity.NbHouseholdValves;
import com.mqtt.ctwingmqtt.mapper.NbHouseholdValvesMapper;
import com.mqtt.ctwingmqtt.service.NbHouseholdValvesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NbHouseholdValvesServiceImpl implements NbHouseholdValvesService {
    @Autowired
    private NbHouseholdValvesMapper nbHouseholdValvesMapper;
    @Override
    public NbHouseholdValves getOne(LambdaQueryWrapper<NbHouseholdValves> temperatureWrapper) {
        NbHouseholdValves nbHouseholdValves = nbHouseholdValvesMapper.selectOne(temperatureWrapper);
        return nbHouseholdValves;
    }

    @Override
    public void save(NbHouseholdValves nbHouseholdValves) {
        nbHouseholdValvesMapper.insert(nbHouseholdValves);
    }

    /**
     * 根据设备地址更新
     * @param nbHouseholdValves
     */
    @Override
    public void updateByAddress(NbHouseholdValves nbHouseholdValves) {
        LambdaQueryWrapper<NbHouseholdValves> updateWrapper = Wrappers.lambdaQuery();
        updateWrapper.eq(NbHouseholdValves::getDeviceAddress, nbHouseholdValves.getDeviceAddress());
        nbHouseholdValvesMapper.update(nbHouseholdValves, updateWrapper);
    }

    /**
     * 条件查询根据设备地址
     * @param deviceAddress
     * @return
     */
    @Override
    public List<NbHouseholdValves> findByDeviceAddress(String deviceAddress) {
        LambdaQueryWrapper<NbHouseholdValves> wrapper = Wrappers.lambdaQuery();
        if (deviceAddress != null && !deviceAddress.isEmpty()) {
            wrapper.eq(NbHouseholdValves::getDeviceAddress, deviceAddress);
        }
        List<NbHouseholdValves> nbHouseholdValves = nbHouseholdValvesMapper.selectList(wrapper);
        return nbHouseholdValves;
    }
}
